package com.hospital.pet.love.lovepethospital.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hospital.pet.love.lovepethospital.domain.PetInfo;
import com.hospital.pet.love.lovepethospital.dto.consumer.PetInfoDto;
import com.hospital.pet.love.lovepethospital.resp.Result;
import com.hospital.pet.love.lovepethospital.resp.ResultCodeEnum;
import com.hospital.pet.love.lovepethospital.service.PetInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author RoselleShaw
 * @create 2024-04-19 16:18
 */
@RestController
@RequestMapping("/pet-info")
@Tag(name = "宠物资料管理")
public class PetInfoController {

    @Resource
    private PetInfoService petInfoService;

    @PostMapping("/save")
    @Operation(summary = "添加或修改宠物资料")
    public Result<Void> add(@RequestBody PetInfoDto petInfoDto) {
        if (petInfoDto.getPetId() != null) {
            petInfoService.update(petInfoDto);
        } else {
            petInfoService.add(petInfoDto);
        }
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/get-by-page/{pageNum}/{pageSize}")
    @Operation(summary = "获取宠物列表")
    public Result<Page<PetInfo>> getByPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        Page<PetInfo> petInfoPage = petInfoService.getByPage(pageNum, pageSize);
        return Result.build(petInfoPage, ResultCodeEnum.SUCCESS);
    }

}
